import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: LineDemo(),
    );
  }
}

class LineDemo extends StatefulWidget {
  @override
  _LineDemoState createState() => _LineDemoState();
}

class _LineDemoState extends State<LineDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('绘制专题')),
      body: Center(
        child: Container(
          width: 500,
          height: 500,
          color: Colors.blue.shade100,
          child: CustomPaint(
            size: Size(500, 500),
            //画布
            //绘制工作
            painter: LinerPainter(),
          ),
        ),
      ),
    );
  }
}

class LinerPainter extends CustomPainter {
  Paint _paint = Paint()
    ..color = Colors.red
    ..strokeCap = StrokeCap.round
    //开启抗锯齿，使边缘更平滑
    ..isAntiAlias = true
    ..strokeWidth = 4;
  @override
  void paint(Canvas canvas, Size size) {
    //绘制点
    // canvas.drawPoints(PointMode.polygon, [
    //   Offset(10, 10),
    //   Offset(100, 200),
    //   Offset(300, 400),
    //   Offset(360, 400),
    // ], _paint);

    canvas.drawLine(Offset(10, 10), Offset(200, 200), _paint);
    canvas.drawLine(Offset(200, 200), Offset(300, 200), _paint);

    canvas.drawLine(Offset(300, 200), Offset(300, 150), _paint);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) {
    return true;
  }
}
